package com.lxq.live;

import com.lxq.live.pojo.RoleEnum;
import com.lxq.live.pojo.User;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class CloneTesting {
    @Test
    void faceClone() {
        var user = new User();
        user.setUserName("张三");
        user.setUserId("three zhang");
        user.setRole(RoleEnum.ordinary);
        try {
            var user2 = (User) user.clone();
            user2.setUserName("李四");
            user2.setUserId("four Li");
            user2.setRole(RoleEnum.admin);
            System.out.println(user2.toString());
            System.out.println(user.toString());
            System.out.println("user==user2：" + (user == user2));
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            System.out.println("克隆失败");
        }
    }

    @Test
    void setCollectionTesting() {
        Set<User> userSet = new HashSet<>();
        var user = new User();
        user.setUserName("张三");
        user.setUserId("three zhang");
        user.setRole(RoleEnum.ordinary);
        userSet.add(user);
        System.out.println(userSet.iterator().next().toString());
    }
}
